package cashpointer.core.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;

/**
 * Klasa do przechowywania danych bankomatu.
 * @author wojciech topolski
 * @version 2009-03-25
 */
@XStreamAlias("Cashpoint")
public class Cashpoint {
    // Identyfikator rekordu w bazie.
    @XStreamOmitField
    private Long id;
    
    // Godziny otwarcia bankomatu.
    @XStreamAlias("time")
    private String time;
    private static int TIME_LENGTH = 100;

    // Wersja update'u od ktorej bankomat jest w bazie.
    @XStreamOmitField
    private String start;
    private static int START_LENGTH = 8;

    // Wersja update'u od ktorej bankomat zostal usuniety.
    @XStreamOmitField
    private String stop;
    private static int STOP_LENGTH = 8;

    // Adres bankomatu.
    @XStreamAlias("Address")
    private Address address;

    // Wlasciciel bankomatu.
    @XStreamOmitField
    private Owner owner;

    // Hashcode bankomatu
    @XStreamAlias("hashcode")
    private int hashcode;

    /**
     * Konstruktor.
     */
    public Cashpoint() {

    }

    /**
     * Zwraca identyfikator rekordu.
     * @return Long
     */
    public Long getId() {
        return id;
    }

    /**
     * Pobiera identyfikator rekordu.
     * @param id Long
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Zwraca godziny otwarcia bankomatu.
     * @return String
     */
    public String getTime() {
        return time;
    }

    /**
     * Pobiera godziny otwarcia bankomatu.
     * @param time String
     */
    public void setTime(String time) {
        if (time != null) {
            this.time = (time.length() > TIME_LENGTH) ? time.substring(0, TIME_LENGTH) : time;
        }
    }

    /**
     * Zwraca adres bankomatu.
     * @return Address
     */
    public Address getAddress() {
        return address;
    }

    /**
     * Pobiera adres bankomatu.
     * @param address Address
     */
    public void setAddress(Address address) {
        this.address = address;
    }

    /**
     * Zwraca wlasciciela bankomatu.
     * @return Owner
     */
    public Owner getOwner() {
        return owner;
    }

    /**
     * Pobiera wlasciciela bankomatu.
     * @param owner Owner
     */
    public void setOwner(Owner owner) {
        this.owner = owner;
    }

    /**
     * Zwraca wersje update'u.
     * @return String
     */
    public String getStart() {
        return start;
    }

    /**
     * Pobiera wersje update'u.
     * @param start String
     */
    public void setStart(String start) {
        if (start != null) {
            this.start = (start.length() > START_LENGTH) ? start.substring(0, START_LENGTH) : start;
        }
    }

    /**
     * Zwraca wersje update'u.
     * @return String
     */
    public String getStop() {
        return stop;
    }

    /**
     * Pobiera wersje update'u.
     * @param start String
     */
    public void setStop(String stop) {
        if (stop != null) {
            this.stop = (stop.length() > STOP_LENGTH) ? stop.substring(0, STOP_LENGTH) : stop;
        }
    }

    /**
     * @return the hashcode
     */
    public int getHashcode() {
        return hashcode;
    }

    /**
     * @param hashcode the hashcode to set
     */
    public void setHashcode(int hashcode) {
        this.hashcode = hashcode;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Cashpoint other = (Cashpoint) obj;
        if (this.address != other.address && (this.address == null || !this.address.equals(other.address))) {
            return false;
        }
        if (this.owner != other.owner && (this.owner == null || !this.owner.equals(other.owner))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.address != null ? this.address.hashCode() : 0);
        hash = 53 * hash + (this.owner != null ? this.owner.hashCode() : 0);
        return hash;
    }
}
